﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ScreenUp
{
    public partial class Form1 : Form
    {
        public static DataFile df = Program.DeserializeDataFile();
        public Form1()
        {
            InitializeComponent();
            host.Text = df.host;
            path.Text = df.path;
            userName.Text = df.username;
            password.Text = df.password;
            HTTPUrl.Text = df.httpurl;
            checkBox1.Checked = df.PreviewBeforeUpload;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            df.host = host.Text;
            df.path = path.Text;
            df.username = userName.Text;
            df.password = password.Text;
            df.httpurl = HTTPUrl.Text;
            df.PreviewBeforeUpload = checkBox1.Checked;
            Program.SerializeDataFile(df);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label7.Text = String.Format(label7.Text, GetType().Assembly.GetName().Version);
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

        private void wholeDesktopToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Desktop();
        }

        private void partOfDesktopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //uploader.Upload(sshotter.GetSnapshot(Program.X, Program.Y, Program.size), userName.Text, password.Text, 25, host.Text, path.Text, HTTPUrl.Text);
            SelectedArea();
        }

        void SelectedArea()
        {
                        ScreenUpSnapshotter sshotter = new ScreenUpSnapshotter();
            ScreenUpFTPUploader uploader = new ScreenUpFTPUploader();
            SQForm_Selector form1 = new SQForm_Selector();
            form1.InstanceRef = this;
            form1.Show();
        }
        private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Hide();
            timer1.Enabled = false;
            panel1.Visible = true;
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
        }

        private void activeWindowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            notifyIcon1.ShowBalloonTip(5, "ScreenGrab", "Select window within the next 5 seconds you want screenshotted", ToolTipIcon.Info);
            Thread.Sleep(5000);

            ActiveWindow();
        }

        internal void Desktop()
        {
            ScreenUpSnapshotter sshotter = new ScreenUpSnapshotter();
            ScreenUpFTPUploader uploader = new ScreenUpFTPUploader();
            uploader.Upload(sshotter.GetSnapshot(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, Screen.PrimaryScreen.Bounds.Size), userName.Text, password.Text, 25, host.Text, path.Text, HTTPUrl.Text);
        }

        internal void ActiveWindow()
        {
            ScreenUpSnapshotter sshotter = new ScreenUpSnapshotter();
            ScreenUpFTPUploader uploader = new ScreenUpFTPUploader();
            ActiveWindowSizeData.RECT rect = ActiveWindowSizeData.GetRectData();
            uploader.Upload(sshotter.GetSnapshot(rect.Left, rect.Top, new Size(rect.Width, rect.Height)), userName.Text, password.Text, 25, host.Text, path.Text, HTTPUrl.Text);
        }

        private void systemHotkey1_Pressed(object sender, EventArgs e)
        {
            this.ActiveWindow();
        }

        private void systemHotkey2_Pressed(object sender, EventArgs e)
        {
            this.SelectedArea();
        }

        private void systemHotkey3_Pressed(object sender, EventArgs e)
        {
            this.Desktop();
        }

        private void previousScreenGrabsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new PrivScreenGrabs().ShowDialog();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new About().Show();
        }
    }
}
